//
//  AnimationSimpleViewController.m
//  UITest
//
//  Created by wp w on 12-6-6.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "AnimationSimpleViewController.h"
#import "DLog.h"

@interface AnimationSimpleViewController ()

@end

@implementation AnimationSimpleViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    CGPoint frameCenter = self.view.center;
	float width = 50.0;
	float height = 50.0;
	
	CGRect viewFrame = CGRectMake(frameCenter.x-width,frameCenter.y-height, width*2, height*2);
    LogRect(@"viewFrame", viewFrame);
	UIView *myView = [[UIView alloc] initWithFrame:viewFrame];
	myView.backgroundColor = [UIColor blueColor];
	
	//create subview
	CGRect subViewFrame = CGRectInset(myView.bounds, width/2.0, height/2.0);
    LogRect(@"subViewFrame", subViewFrame);
	UIView *mySubview = [[UIView alloc] initWithFrame:subViewFrame];
	mySubview.backgroundColor = [UIColor yellowColor];
	
	//set autoresizing mask
	mySubview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
	
	[myView addSubview:mySubview];
    
	[[self view] addSubview:myView];
	
	//animate resize
    //此时已经有了一个小的view
    //动画开始，执行1秒钟。动画结束时要求变为一个大的view
    //动画提交
	[UIView beginAnimations:nil context:NULL];
	
	[UIView setAnimationDuration:1.0];
	viewFrame = CGRectInset(viewFrame, -width, -height);
    LogRect(@"viewFrame", viewFrame);
	[myView setFrame:viewFrame];
	
	[UIView commitAnimations];
	
	[mySubview release];
	[myView release];	
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
